package org.agilelang.object;

import org.agilelang.object.ObjectAttribute;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Roderick
 */
@XmlRootElement(name = "agileclass")
public class ObjectClass {

    String type = "";
    String name = "";
    String extend = "";

    public String getExtend() {
        return extend;
    }

    @XmlAttribute
    public void setExtend(String extend) {
        this.extend = extend;
    }

    List<ObjectClassAttribute> classattributes = new ArrayList<>();

    List<ObjectAttribute> attributes = new ArrayList<>();
    List<ObjectFunction> functions = new ArrayList<>();
    List<ObjectView> views = new ArrayList<>();

    public String getType() {
        return type;
    }

    @XmlAttribute
    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public String getNameParam() {
        for (ObjectClassAttribute fun : classattributes) {
            if (fun.getName().equals("name")) {

                return fun.getValue();
            }
        }
        return "";
    }

    @XmlAttribute
    public void setName(String name) {
        this.name = name;
    }

    public List<ObjectClassAttribute> getClassattributes() {
        return classattributes;
    }

    public void setClassattributes(List<ObjectClassAttribute> classattributes) {
        this.classattributes = classattributes;
    }

    public void addClassattribute(ObjectClassAttribute classattributes) {
        this.classattributes.add(classattributes);
    }

    public List<ObjectAttribute> getAttributes() {
        return attributes;
    }

    public void setAttributes(List<ObjectAttribute> attributes) {
        this.attributes = attributes;
    }

    public void addAttribute(ObjectAttribute attribute) {
        this.attributes.add(attribute);
    }

    public List<ObjectFunction> getFunctions() {
        return functions;
    }

    public void setFunctions(List<ObjectFunction> functions) {
        this.functions = functions;
    }

    public List<ObjectView> getViews() {
        return views;
    }

    public void setViews(List<ObjectView> views) {
        this.views = views;
    }

    public String getDefineTemplate(String key) {
        for (ObjectFunction fun : functions) {
            if (fun.getName().equals("defineTemplate")) {
                for (ObjectParam attr : fun.getParams()) {
                    if (attr.getName().equals(key)) {
                        return attr.getValue();
                    }
                }
            }
        }
        return "";
    }

    public boolean isFunctionAddAttrribute(String key) {
        for (ObjectFunction fun : functions) {
            if (fun.getName().equals("addAttribute") && fun.getDefine("type").equals(key)) {
                return true;
            }
        }
        return false;
    }

    public String getFunctionAddAttrributeParam(String name_function, String name_param) {
        for (ObjectFunction fun : functions) {
            if (fun.getName().equals("addAttribute") && fun.getDefine("type").equals(name_function)) {
                return fun.getDefine(name_param);
            }
        }
        return "";
    }
}
